﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Ultimus.OC;
using Ultimus.WFServer;
using H2.NET.Common;

namespace H2.NET.Web.Workflow
{
    public partial class Inbox2 : System.Web.UI.Page
    {
        [SessionType]
        public clsCommon clsCmm = new clsCommon();

        [SessionType]
        string strProcessName = "";

        string strType = "";
        string[] strRange = new string[2] { "", "" };

        #region 事件 页面 加载
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Response.Buffer = true;
                Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
                Response.Expires = 0;
                Response.CacheControl = "no-cache";

                //如果是超时以及未登陆系统的情况
                if (!clsCmm.isLogin(User.Identity.Name, User.Identity.AuthenticationType))
                {
                    string strUserName = Request.QueryString["UserName"];
                    if (string.IsNullOrEmpty(strUserName) || Util.Decode(strUserName).IndexOf('/') == -1)
                    {
                        //转入登陆界面
                        Response.Write(Util.GoToWebPath(ResolveUrl("~/logon.aspx")));
                    }
                    else
                    {
                        clsCmm.chkLogin(Util.Decode(strUserName));
                    }                    
                }

                //added by 
                strProcessName = Request.QueryString["process"];
                strType        = Request.QueryString["type"];

                if (!string.IsNullOrEmpty(strProcessName))
                {
                    img_btn_AssignConfer.Visible = false;
                    img_btn_AssignConfer.Visible = false;
                    img_btn_cancel.Visible = false;
                    img_btn_personal_info.Visible = false;
                    lblAssignConfer.Visible = false;
                    lblTakeBack.Visible = false;
                    lblPersonalInfo.Visible = false;
                }

                //第一次加载页面时初始化
                if (!Page.IsPostBack)
                {
                    #region 语言设置
                    //语言设置
                    btnSearch.Text = clsCmm.getTextValue("frm_inbox_btnSearch");
                    btnAssignTo.Text = clsCmm.getTextValue("frm_inbox_btn_assign_to");
                    btnConferTo.Text = clsCmm.getTextValue("frm_inbox_btn_confer_to");
                    lblUntileDate.Text = clsCmm.getTextValue("frm_inbox_untile_date");
                    lblSearch.Text = clsCmm.getTextValue("frm_initiate_btnSearch");
                    lblAssignConfer.Text = clsCmm.getTextValue("frm_inbox_txt_assign_confer");
                    lblTakeBack.Text = clsCmm.getTextValue("frm_inbox_txt_take_back");
                    lblPersonalInfo.Text = clsCmm.getTextValue("frm_inbox_txt_persoanl_info");

                    btnTakeBack.Visible = false;
                    btnTakebackAllFutureTask.Visible = false;
                    btnTakeBack.Text = clsCmm.getTextValue("frm_inbox_txt_take_back");
                    btnAddDelete.Visible = false;
                    btnAddDelete.Text = clsCmm.getTextValue("frm_inbox_personal_info_btn_save");

                    //设置名称及是否可见
                    btnTakebackAllFutureTask.Text = clsCmm.getTextValue("frm_inbox_btn_take_bake_all_future_task");
                    btnCancel.Visible = false;
                    lblCancel.Text = clsCmm.getTextValue("frm_inbox_btnCancel");
                    btnCancel.Text = clsCmm.getTextValue("frm_inbox_btnCancel");

                    #endregion

                    #region 弹出框
                    //指派人员选择对话框参数初始化
                    txtAssignConferTo.Dialog_ID = Util.AppSettings("associate").ToLower() == "yes" ? "SYS-0008" : "SYS-0007";
                    txtAssignConferTo.Dialog_Is_Click   = true;
                    txtAssignConferTo.Dialog_Language   = clsCmm.comm_language;
                    txtAssignConferTo.Dialog_Value      = "a";
                    txtAssignConferTo.Dialog_Width      = "300";
                    txtAssignConferTo.Dialog_Height     = "360";

                    //设置同事选择对话框参数初始化
                    txtAssociate.Dialog_ID              = "SYS-0007";
                    txtAssociate.Dialog_Is_Click        = true;
                    txtAssociate.Dialog_Language        = clsCmm.comm_language;
                    txtAssociate.Dialog_Value           = "a";
                    txtAssociate.Dialog_Width           = "300";
                    txtAssociate.Dialog_Height          = "360";
                    #endregion

                    #region 任务指派类型下拉框初始化
                    //任务指派类型下拉框
                    drpOptions.Items.Clear();
                    drpOptions.Items.Add(new ListItem(clsCmm.getTextValue("frm_inbox_txt_only_selected_tasks"), "A"));
                    drpOptions.Items.Add(new ListItem(clsCmm.getTextValue("frm_inbox_txt_all_current_tasks"), "B"));
                    drpOptions.Items.Add(new ListItem(clsCmm.getTextValue("frm_inbox_txt_all_future_tasks"), "C"));
                    drpOptions.SelectedIndex = 0;
                    lblUntileDate.Visible = false;
                    txtUntileDate.Visible = false;
                    #endregion

                    //查询并对列表进行数据绑定
                    load_rep_group_list();
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 Page_Load 事件出错：" + ee.Message);
            }
        }
        #endregion

        #region 事件 显示/隐藏 Search 条件
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void img_btn_Search_Click(object sender, ImageClickEventArgs e)
        {
            //设置查询条件是否显示
            e_element_tr_take_back.Value = "none";
            e_element_tr_cancel.Value = "none";
            set_e_element_tr_search_show();

            //查询并对列表进行数据绑定
            load_rep_group_list();
            foreach (RepeaterItem ri in gvInbox.Items)
            {
                ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;
                Repeater rpt = ri.FindControl("dv_show") as Repeater;
                strRange = imgG.CommandArgument.ToString().Split('~');

                if (imgG.CommandName == "Shrink")
                {
                    load_gv_inbox_list(rpt);
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lblSearch_Click(object sender, EventArgs e)
        {
            //设置查询条件是否显示
            e_element_tr_take_back.Value = "none";
            e_element_tr_cancel.Value = "none";
            set_e_element_tr_search_show();

            //查询并对列表进行数据绑定
            load_rep_group_list();
            foreach (RepeaterItem ri in gvInbox.Items)
            {
                ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;
                Repeater rpt = ri.FindControl("dv_show") as Repeater;
                strRange = imgG.CommandArgument.ToString().Split('~');

                if (imgG.CommandName == "Shrink")
                {
                    load_gv_inbox_list(rpt);
                }
            }
        }
        #endregion

        #region 事件 显示/隐藏 Assign & Confer 条件
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void img_btn_AssignConfer_Click(object sender, ImageClickEventArgs e)
        {
            //设置查询条件是否显示
            set_e_element_tr_assign_tasks_show();

            //查询并对列表进行数据绑定
            load_rep_group_list();
            foreach (RepeaterItem ri in gvInbox.Items)
            {
                ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;
                Repeater rpt = ri.FindControl("dv_show") as Repeater;
                strRange = imgG.CommandArgument.ToString().Split('~');

                if (imgG.CommandName == "Shrink")
                {
                    load_gv_inbox_list(rpt);
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lblAssignConfer_Click(object sender, EventArgs e)
        {
            set_e_element_tr_assign_tasks_show();

            //查询并对列表进行数据绑定
            load_rep_group_list();
            foreach (RepeaterItem ri in gvInbox.Items)
            {
                ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;
                Repeater rpt = ri.FindControl("dv_show") as Repeater;
                strRange = imgG.CommandArgument.ToString().Split('~');

                if (imgG.CommandName == "Shrink")
                {
                    load_gv_inbox_list(rpt);
                }
            }
        }
        #endregion

        #region 事件 显示/隐藏 Take Back 条件
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void img_btn_TakeBack_Click(object sender, ImageClickEventArgs e)
        {
            //设置查询条件是否显示
            set_e_element_tr_take_back_show();

            //查询并对列表进行数据绑定
            load_rep_group_list();
            foreach (RepeaterItem ri in gvInbox.Items)
            {
                ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;
                Repeater rpt = ri.FindControl("dv_show") as Repeater;
                strRange = imgG.CommandArgument.ToString().Split('~');

                imgG.CommandName = "Shrink";
                imgG.ImageUrl = "~/Resource/Images/cmm_dot_expand.gif";

                if (imgG.CommandName == "Shrink")
                {
                    load_gv_inbox_list(rpt);
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lblTakeBack_Click(object sender, EventArgs e)
        {
            //设置查询条件是否显示
            set_e_element_tr_take_back_show();

            //查询并对列表进行数据绑定
            load_rep_group_list();
            foreach (RepeaterItem ri in gvInbox.Items)
            {
                ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;
                Repeater rpt = ri.FindControl("dv_show") as Repeater;
                strRange = imgG.CommandArgument.ToString().Split('~');

                imgG.CommandName = "Shrink";
                imgG.ImageUrl = "~/Resource/Images/cmm_dot_expand.gif";

                if (imgG.CommandName == "Shrink")
                {
                    load_gv_inbox_list(rpt);
                }
            }

        }
        #endregion

        #region 事件 显示/隐藏 Cancel 条件
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void img_btn_cancel_Click(object sender, ImageClickEventArgs e)
        {
            //设置查询条件是否显示
            set_e_element_tr_cancel_show();

            //查询并对列表进行数据绑定
            load_rep_group_list();
            foreach (RepeaterItem ri in gvInbox.Items)
            {
                ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;
                Repeater rpt = ri.FindControl("dv_show") as Repeater;
                strRange = imgG.CommandArgument.ToString().Split('~');

                imgG.CommandName = "Shrink";
                imgG.ImageUrl = "~/Resource/Images/cmm_dot_expand.gif";

                if (imgG.CommandName == "Shrink")
                {
                    load_gv_inbox_list(rpt);
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lblCancel_Click(object sender, EventArgs e)
        {
            //设置查询条件是否显示
            set_e_element_tr_cancel_show();

            //查询并对列表进行数据绑定
            load_rep_group_list();
            foreach (RepeaterItem ri in gvInbox.Items)
            {
                ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;
                Repeater rpt = ri.FindControl("dv_show") as Repeater;
                strRange = imgG.CommandArgument.ToString().Split('~');

                imgG.CommandName = "Shrink";
                imgG.ImageUrl = "~/Resource/Images/cmm_dot_expand.gif";

                if (imgG.CommandName == "Shrink")
                {
                    load_gv_inbox_list(rpt);
                }
            }
        }
        #endregion

        #region 事件 显示/隐藏 Personal Info 条件
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void img_btn_personal_info_Click(object sender, ImageClickEventArgs e)
        {
            //设置Personal Infomation是否显示
            set_element_tr_personal_infomation_show();

            //取得同事列表
            get_all_associate();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lblPersonalInfo_Click(object sender, EventArgs e)
        {
            //设置Personal Infomation是否显示
            set_element_tr_personal_infomation_show();

            //取得同事列表
            get_all_associate();
        }
        #endregion

        #region 事件 GridView 行数据绑定
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvInbox_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    e.Row.Attributes.Add("id", "tr_row_" + e.Row.Cells[0].Text);
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 gvInbox_RowDataBound事件出错：" + ee.Message);
            }
        }
        #endregion

        #region 事件 单击 Search(查询) 按钮
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                //查询条件显示
                set_e_element_tr_search_show();

                //查询并对列表进行数据绑定
                foreach (RepeaterItem ri in gvInbox.Items)
                {
                    ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;
                    Repeater rpt = ri.FindControl("dv_show") as Repeater;
                    strRange = imgG.CommandArgument.ToString().Split('~');

                    if (imgG.CommandName == "Shrink")
                    {
                        load_gv_inbox_list(rpt);
                    }
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 btnSearch_Click 事件出错：" + ee.Message);
            }
        }
        #endregion

        #region 事件 单击 AssignTo(任务指派) 按钮
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAssignTo_Click(object sender, EventArgs e)
        {
            //设置查询区域隐藏
            set_e_element_tr_assign_tasks_show();

            //Take Bake 按钮是否显示
            if (e_element_tr_take_back.Value == "block")
            {
                btnTakeBack.Visible = true;
            }
            else
            {
                btnTakeBack.Visible = false;
            }

            //保存变量
            txtAssignConferTo.Text = txtAssignConferTo_save.Value;

            //数据验证
            if (txtAssignConferToAD.Value == "")
            {
                lblAssignConferErr.Text = clsCmm.getTextValue("frm_inbox_txt_assign_confer_err");
                return;
            }

            //清空出错信息
            lblAssignConferErr.Text = "";

            //执行任务指派
            assign_tasks();
        }
        #endregion

        #region 事件 单击 ConfernTo(任务会办) 按钮
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnConferTo_Click(object sender, EventArgs e)
        {
            //设置查询区域隐藏
            set_e_element_tr_assign_tasks_show();

            //保存变量
            txtAssignConferTo.Text = txtAssignConferTo_save.Value;

            //数据验证
            if (txtAssignConferToAD.Value == "")
            {
                lblAssignConferErr.Text = clsCmm.getTextValue("frm_inbox_txt_assign_confer_err");
                return;
            }

            //清空出错信息
            lblAssignConferErr.Text = "";

            //执行任务会办
            confer_tasks();
        }
        #endregion

        #region 事件 单击 Take Back (任务收回) 按钮
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnTakeBack_Click(object sender, EventArgs e)
        {
            //设置查询区域隐藏
            set_e_element_tr_take_back_show();

            //执行任务指派
            take_back_tasks();
        }
        #endregion

        #region 事件 单击 Take Back All future task(所有将来任务收回) 按钮
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnTakebackAllFutureTask_Click(object sender, EventArgs e)
        {
            try
            {
                int intCNT = 0;
                string strSQL = "delete from assignment where taskuser='" + clsCmm.comm_username + "' and processname is null and stepid is null and steplabel is null and assignuntil is not null";
                clsCmm.clsDB.Storage("bpmDB");
                intCNT = clsCmm.clsDB.ExcuteSql(strSQL);

                //如果结果返回值 > 1 的情况，返回 true，否则返回 false
                if (intCNT >= 1)
                {
                    lblTakeBackErr.Text = clsCmm.getTextValue("frm_inbox_txt_take_back_success");
                    btnTakebackAllFutureTask.Visible = false;
                }
                else
                {
                    lblTakeBackErr.Text = clsCmm.getTextValue("frm_inbox_txt_take_back_failed");
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 btnTakebackAllFutureTask_Click方法出错：" + ee.Message);
                lblTakeBackErr.Text = clsCmm.getTextValue("frm_inbox_txt_take_back_failed");
            }
        }
        #endregion

        #region 事件 单击 Cancel (取消实例) 按钮
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            //设置查询区域隐藏
            set_e_element_tr_cancel_show();

            //执行任务取消
            cancel_tasks();
        }
        #endregion

        #region 事件 单击 Add、Delete(加入列表、移出列表) 按钮
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAddDelete_Click(object sender, EventArgs e)
        {
            try
            {
                //设置同事列表
                set_all_associate();

                //重新取得同事列表
                get_all_associate();

                //清空“同事”选择项
                txtAssociateAD.Value = "";
                txtAssociate.Text = "";
                btnAddDelete.Visible = false;
                is_in_all_txtAssociate.Value = "";
                is_email_changed.Value = "";
                btnAddDelete.Text = clsCmm.getTextValue("frm_inbox_personal_info_btn_save");
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 btnAddDelete_Click 事件出错：" + ee.Message);
            }
        }
        #endregion

        #region 事件 索引变更 Options 下拉框
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void drpOptions_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                //设置查询区域隐藏
                set_e_element_tr_assign_tasks_show();

                //如果选择的是 所有将来的任务 选择的情况
                if (drpOptions.SelectedValue == "C")
                {
                    lblUntileDate.Visible = true;
                    txtUntileDate.Visible = true;
                    btnConferTo.Visible = false;
                }
                else
                {
                    lblUntileDate.Visible = false;
                    txtUntileDate.Visible = false;
                    btnConferTo.Visible = true;
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 drpOptions_SelectedIndexChanged 事件出错：" + ee.Message);
            }
        }
        #endregion

        #region 事件 文本变化 Associate
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void txtAssociate_TextChanged(object sender, EventArgs e)
        {
            try
            {
                //是否显示 Add、Delete 按钮
                lblAssociateErr.Text = "";
                btnAddDelete.Visible = true;
                if (txtAssociateAD.Value.Trim() != "" && txtAssociate.Text.Trim() != "")
                {
 
                }
                else
                {
                    is_in_all_txtAssociate.Value = "";
                    btnAddDelete.Text = clsCmm.getTextValue("frm_inbox_personal_info_btn_save");
                    if (is_email_changed.Value.Trim() == "")
                    {
                        btnAddDelete.Visible = false;
                    }
                    else
                    {
                        btnAddDelete.Visible = true;
                    }
                    return;
                }

                //对所有的AssociateAD进行拆分 
                bool Flg = false;
                string[] arrAssociateAD = all_txtAssociateAD.Value.ToString().Split(';');

                //循环判断是否已存在于当前列表
                for (int i = 0; i < arrAssociateAD.Length; i++ )
                {
                    if (txtAssociateAD.Value.Trim().ToLower() == arrAssociateAD[i].Trim().ToLower())
                    {
                        Flg = true;
                        break;
                    }
                }

                //初始化Add、Delete按钮
                if (Flg)
                {
                    btnAddDelete.Text = clsCmm.getTextValue("frm_inbox_personal_info_btn_delete");
                    is_in_all_txtAssociate.Value = "delete";
                }
                else
                {
                    btnAddDelete.Text = clsCmm.getTextValue("frm_inbox_personal_info_btn_add");
                    is_in_all_txtAssociate.Value = "add";
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 txtAssociate_TextChanged方法出错：" + ee.Message);
            }
        }
        #endregion

        #region 事件 文本变化 Email
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void txtEmail_TextChanged(object sender, EventArgs e)
        {
            //如果“选择同事框”在没有选择的情况
            btnAddDelete.Visible = true;
            lblAssociateErr.Text = "";
            is_email_changed.Value = "changed";
            if(txtAssociate.Text.Trim() == "")
            {
                btnAddDelete.Text = clsCmm.getTextValue("frm_inbox_personal_info_btn_save");
            }
        }
        #endregion

        #region 事件 单击 Check Items All 复选框
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void chk_items_all_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chk_items_all = (CheckBox)sender;

            //获取有跟进记录的项目
            foreach (RepeaterItem ri in gvInbox.Items)
            {
                Repeater rpt = ri.FindControl("dv_show") as Repeater;
                ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;

                if (imgG.CommandName == "Shrink")
                {
                    foreach (RepeaterItem row in rpt.Items)
                    {
                        ((CheckBox)row.FindControl("chk_items")).Checked = chk_items_all.Checked;
                    }
                }
            }
        }
        #endregion

        #region 事件 明细行命令
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvInbox_ItemCommand(object sender, RepeaterCommandEventArgs e)
        {
            if (e.CommandName != "Expand" && e.CommandName != "Shrink")
            {
                return;
            }

            //如果是行命令的情况
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                strRange = e.CommandArgument.ToString().Split('~');
                ImageButton imgG = e.Item.FindControl("imgGroup") as ImageButton;
                Repeater rpt = e.Item.FindControl("dv_show") as Repeater;

                if (imgG.CommandName == "Expand")
                {
                    load_gv_inbox_list(rpt);
                    rpt.Visible = true;
                }
                else
                {
                    rpt.Visible = false;
                }

                imgG.CommandName = imgG.CommandName == "Expand" ? "Shrink" : "Expand";
                imgG.ImageUrl = imgG.CommandName == "Expand" ? "~/Resource/Images/cmm_dot_shrink.gif" : "~/Resource/Images/cmm_dot_expand.gif";
            }
        }
        #endregion

        #region 方法 获取收件箱列表
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public DataTable get_all_inbox()
        {
            try
            {
                string strSQL = "";
                string strUserName = clsCmm.comm_username;
                string strSummary = txtSummary.Text.Trim().Replace(",", "',").Replace("'", "''");
                string strIncidentNoFrom = txtIncidentFrom.Text.Trim().Replace(".", "");
                string strIncidentNoTo = txtIncidentTo.Text.Trim().Replace(".", "");

                //查询过滤中Process下拉列表中的值
                string strProcess = "all";
                if (drpProcess.SelectedItem != null)
                {
                    strProcess = drpProcess.SelectedItem.Value.Trim();
                }

                //string strStep = "all";
                //if (drpStep.SelectedItem != null)
                //{
                //    strStep = drpStep.SelectedItem.Value.Trim();
                //}

                //查找收件箱列表
                strSQL = "";
                strSQL += "select distinct d.*,";
                strSQL += " '' as initiator_name,";
                strSQL += " '' as taskuser_name,";
                strSQL += " '' as assignedtouser_name";
                strSQL += "  from (select b.*, c.summary, c.priority, c.initiator";
                strSQL += "  from (select rtrim(a.taskid) as taskid";
                //中文的情况，流程名变化
                if (clsCmm.comm_language == "en-us" && Util.AppSettings("language").ToLower() == "yes")
                {
                    strSQL += " ,h.processhelpurl as processname3";
                    strSQL += " ,h.processname";
                }
                else
                {
                    strSQL += " ,a.processname as processname3";
                    strSQL += " ,a.processname";
                }

                strSQL += " ,rtrim(a.helpurl) as helpurl";
                strSQL += " ,'' as openform";

                strSQL += " ,a.incident";
                strSQL += " ,a.steplabel";
                strSQL += " ,a.taskuser";
                strSQL += " ,a.assignedtouser";
                strSQL += " ,'' as img_status";     //状态图标
                strSQL += " ,'' as img_monitor";    //监控图标
                strSQL += " ,a.status";
                strSQL += " ,a.substatus";
                strSQL += " ,a.starttime";
                strSQL += " ,a.delaytime";
                strSQL += " ,a.overduetime";
                strSQL += " ,a.urgentduetime";

                #region 查询字段(暂时不用)
                //strSQL += "                    ,a.qstarttime,";
                //strSQL += "                    ,a.qendtime,";
                //strSQL += "                    ,a.recipienttype";
                //strSQL += "                    ,a.recipient";
                //strSQL += "                    ,a.stepid";
                //strSQL += "                    ,a.processversion";
                //strSQL += "                    ,a.taskrate";
                //strSQL += "                    ,a.tasktime";
                //strSQL += "                    ,a.cost";
                //strSQL += "                      ,a.endtime";
                #endregion

                strSQL += "  from tasks a, initiate h";    //with(readpast,rowlock)
                strSQL += " where 1=1 and a.processname=h.processname";
                strSQL += " and a.taskid not in(select taskid from taskqueue)";
                strSQL += " and a.starttime >='" + strRange[0] + "'";
                strSQL += " and a.starttime <'" + strRange[1] + "'";

                //如果是 Take Back 的情况
                if (e_element_tr_search.Value == "block" && e_element_tr_take_back.Value == "block")
                {
                    strSQL += " and lower(a.taskuser) = lower('" + strUserName + "')";
                    strSQL += " and lower(a.assignedtouser) <> lower('" + strUserName + "')";
                    strSQL += " and a.status = 1";
                }
                //如果是 Cancel 的情况
                else if (e_element_tr_search.Value == "block" && e_element_tr_cancel.Value == "block")
                {
                    strSQL += " and (rtrim(a.steplabel) + rtrim(a.stepid)) in(select rtrim(steplabel) + rtrim(stepid) from processsteps where steptype=2)";
                    strSQL += " and lower(a.assignedtouser) = lower('" + strUserName + "')";
                    strSQL += " and (rtrim(a.processname) + rtrim(a.incident)) in (select (rtrim(processname) + rtrim(incident)) from incidents where status=1 and lower(initiator)=lower('" + strUserName + "'))";
                }
                else
                {
                    strSQL += " and lower(a.assignedtouser) = lower('" + strUserName + "')";
                    strSQL += " and a.status = 1";
                }
                

                //查询过滤
                if (strProcess != "all")
                {
                    strSQL = strSQL + " and a.processname = '" + strProcess + "'";
                }

                //added by
                if (!string.IsNullOrEmpty(strProcessName))
                {
                    strSQL = strSQL + " and a.processname = '" + strProcessName + "'";
                }                

                //if (strStep != "all")
                //{
                //    strSQL = strSQL + " and a.steplabel = '" + strStep + "'";
                //}

                if (strIncidentNoFrom != "")
                {
                    strSQL = strSQL + " and a.incident >= " + strIncidentNoFrom + "";
                }

                if (strIncidentNoTo != "")
                {
                    strSQL = strSQL + " and a.incident <= " + strIncidentNoTo + "";
                }

                strSQL += " ) b";
                strSQL += " left join incidents c on b.processname = c.processname";
                strSQL += " and b.incident = c.incident) d";
 
                //摘要
                if (strSummary != "")
                {
                    strSQL = strSQL + " where d.summary like '%" + strSummary + "%'";
                }

                TaskDB.Log("", true, "调用 inbox.aspx 页面 get_all_inbox 方法SQL：" + strSQL);
                clsCmm.clsDB.Storage("bpmDB");
                DataTable dt = clsCmm.clsDB.Query(strSQL);

                //在没有结果返回的情况，返回一空白行
                if (dt.Rows.Count == 0)
                {
                    DataRow dr = dt.NewRow();
                    dt.Rows.Add(dr);
                }

                return dt;
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region 方法 查询分组列表并进行数据绑定
        /// <summary>
        /// 
        /// </summary>
        public void load_rep_group_list()
        {
            try
            {
                strType = string.IsNullOrEmpty(strType) ? "1" : strType;

                //加载列表
                DataTable dt = new DataTable();
                dt.Clear();

                dt.Columns.Add("Title");
                dt.Columns.Add("Range");

                //如果是 Take Back 的情况
                if (e_element_tr_search.Value == "block" && e_element_tr_take_back.Value == "block")
                {
                    DataRow dr = dt.NewRow();
                    dr[0] = clsCmm.getTextValue("frm_inbox_grp_can_tack_back");
                    dr[1] = "2000-01-01" + "~" + System.DateTime.Today.AddDays(1).ToString("yyyy-MM-dd");
                    dt.Rows.Add(dr);
                }
                //如果是 Cancel 的情况
                else if (e_element_tr_search.Value == "block" && e_element_tr_cancel.Value == "block")
                {
                    DataRow dr = dt.NewRow();
                    dr[0] = clsCmm.getTextValue("frm_inbox_grp_can_cancel");
                    dr[1] = "2000-01-01" + "~" + System.DateTime.Today.AddDays(1).ToString("yyyy-MM-dd");
                    dt.Rows.Add(dr);
                }
                else
                {
                    //按周进行统计
                    if (strType == "1")
                    {
                        DataRow dr = dt.NewRow();
                        dr[0] = clsCmm.getTextValue("frm_complete_grp_today");
                        dr[1] = System.DateTime.Today.ToString("yyyy-MM-dd") + "~" + System.DateTime.Today.AddDays(1).ToString("yyyy-MM-dd");
                        dt.Rows.Add(dr);

                        DataRow dr2 = dt.NewRow();
                        dr2[0] = clsCmm.getTextValue("frm_complete_grp_yesterday");
                        dr2[1] = System.DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd") + "~" + System.DateTime.Today.ToString("yyyy-MM-dd");
                        dt.Rows.Add(dr2);

                        if (System.DateTime.Today.DayOfWeek != DayOfWeek.Monday && System.DateTime.Today.DayOfWeek != DayOfWeek.Tuesday)
                        {
                            DataRow dr3 = dt.NewRow();
                            dr3[0] = clsCmm.getTextValue("frm_complete_grp_week");
                            dr3[1] = System.DateTime.Today.AddDays(-1 * (System.DateTime.Today.DayOfWeek == DayOfWeek.Sunday ? 6 : (int)System.DateTime.Today.DayOfWeek - 1)).ToString("yyyy-MM-dd") + "~" + System.DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd");
                            dt.Rows.Add(dr3);
                        }

                        DataRow dr4 = dt.NewRow();
                        dr4[0] = clsCmm.getTextValue("frm_complete_grp_last_week");
                        dr4[1] = System.DateTime.Today.AddDays((-1 * (System.DateTime.Today.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)System.DateTime.Today.DayOfWeek)) - 6).ToString("yyyy-MM-dd") + "~" + System.DateTime.Today.AddDays((-1 * (System.DateTime.Today.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)System.DateTime.Today.DayOfWeek)) + 1).ToString("yyyy-MM-dd");
                        dt.Rows.Add(dr4);

                        DataRow dr5 = dt.NewRow();
                        dr5[0] = clsCmm.getTextValue("frm_complete_grp_2_week_ago");
                        dr5[1] = System.DateTime.Today.AddDays((-1 * (System.DateTime.Today.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)System.DateTime.Today.DayOfWeek)) - 13).ToString("yyyy-MM-dd") + "~" + System.DateTime.Today.AddDays((-1 * (System.DateTime.Today.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)System.DateTime.Today.DayOfWeek)) - 6).ToString("yyyy-MM-dd");
                        dt.Rows.Add(dr5);

                        DataRow dr6 = dt.NewRow();
                        dr6[0] = clsCmm.getTextValue("frm_complete_grp_earlier");
                        dr6[1] = "2000-01-01" + "~" + System.DateTime.Today.AddDays((-1 * (System.DateTime.Today.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)System.DateTime.Today.DayOfWeek)) - 13).ToString("yyyy-MM-dd");
                        dt.Rows.Add(dr6);
                    }

                    //按月进行统计
                    if (strType == "2")
                    {
                        DataRow dr = dt.NewRow();
                        dr[0] = clsCmm.getTextValue("frm_complete_grp_this_month");
                        dr[1] = System.DateTime.Today.ToString("yyyy-MM") + "-1" + "~" + System.DateTime.Today.AddDays(1).ToString("yyyy-MM-dd");
                        dt.Rows.Add(dr);

                        DataRow dr2 = dt.NewRow();
                        dr2[0] = clsCmm.getTextValue("frm_complete_grp_last_month");
                        dr2[1] = System.DateTime.Today.AddMonths(-1).ToString("yyyy-MM") + "-1" + "~" + System.DateTime.Today.ToString("yyyy-MM") + "-1";
                        dt.Rows.Add(dr2);

                        DataRow dr3 = dt.NewRow();
                        dr3[0] = clsCmm.getTextValue("frm_complete_grp_earlier");
                        dr3[1] = "2000-01-01" + "~" + System.DateTime.Today.AddMonths(-1).ToString("yyyy-MM") + "-1";
                        dt.Rows.Add(dr3);
                    }
                }

                gvInbox.DataSource = dt;
                gvInbox.DataBind();
            }
            catch
            {
                //TaskDB.Log("", false, "调用 complete.aspx 页面 load_gv_complete_list方法出错：" + ee.Message);
            }
        }
        #endregion

        #region 方法 查询并对列表进行数据绑定
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void load_gv_inbox_list(Repeater rep)
        {
            try
            {
                //加载列表
                DataTable dt = get_all_inbox();

                //数据合法性检查
                if (dt == null)
                {
                    return;
                }

                #region added by zk 2009-12-21 start
                //取得所有的用户账号对应用户姓名             
                string str_user_name = "";
                DataTable dt2 = new DataTable();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    //initiator
                    if (str_user_name.IndexOf(",'" + dt.Rows[i]["initiator"].ToString().Trim() + "'") == -1)
                    {
                        str_user_name += ",'" + dt.Rows[i]["initiator"].ToString().Trim() + "'";
                    }

                    //taskuser
                    if (str_user_name.IndexOf(",'" + dt.Rows[i]["taskuser"].ToString().Trim() + "'") == -1)
                    {
                        str_user_name += ",'" + dt.Rows[i]["taskuser"].ToString().Trim() + "'";
                    }

                    //assignedtouser
                    if (str_user_name.IndexOf(",'" + dt.Rows[i]["assignedtouser"].ToString().Trim() + "'") == -1)
                    {
                        str_user_name += ",'" + dt.Rows[i]["assignedtouser"].ToString().Trim() + "'";
                    }
                }

                //从数据库中查询用户信息
                string strSQL = "select rtrim(FULLNAME) as UserFullName,lower(rtrim(Name)) as UserShortName from JOBS where lower(rtrim(Name)) in('-1'" + str_user_name + ")";
                clsCmm.clsDB.Storage("bpmDB");
                dt2 = clsCmm.clsDB.Query(strSQL);
                #endregion added by zk 2009-12-21 end

                //设置状态列的图片
                for (int i = 0; i < dt.Rows.Count; i++)
                {

                    //处理表单类型 (自定义表单 & 标准表单)
                    string HelpUrl = dt.Rows[i]["helpurl"].ToString();
                    if (!string.IsNullOrEmpty(HelpUrl) && HelpUrl.Length >= 5 && HelpUrl.Substring(0, 5).ToLower() == "form:")
                    {
                        dt.Rows[i]["openform"] = HelpUrl.Substring(5, HelpUrl.Length - 5);
                    }
                    else
                    {
                        dt.Rows[i]["openform"] = "openform.aspx";
                    }

                    #region added by zk 2009-12-21 start
                    //循环设置用户信息
                    for (int j = 0; j < dt2.Rows.Count; j++)
                    {
                        //initiator
                        if (dt.Rows[i]["initiator"].ToString().ToLower().Trim() == dt2.Rows[j]["UserShortName"].ToString().ToLower().Trim())
                        {
                            dt.Rows[i]["initiator_name"] = dt2.Rows[j]["UserFullName"].ToString().Trim();
                        }

                        //taskuser
                        if (dt.Rows[i]["taskuser"].ToString().ToLower().Trim() == dt2.Rows[j]["UserShortName"].ToString().ToLower().Trim())
                        {
                            dt.Rows[i]["taskuser_name"] = dt2.Rows[j]["UserFullName"].ToString().Trim();
                        }

                        //assignedtouser
                        if (dt.Rows[i]["assignedtouser"].ToString().ToLower().Trim() == dt2.Rows[j]["UserShortName"].ToString().ToLower().Trim())
                        {
                            dt.Rows[i]["assignedtouser_name"] = dt2.Rows[j]["UserFullName"].ToString().Trim();
                        }
                    }
                    #endregion added by zk 2009-12-21 end

                    //流程状态图标
                    switch (dt.Rows[i]["substatus"].ToString().Trim())
                    {
                        case "0":
                        case "1":
                            dt.Rows[i]["img_status"] = "frm_inbox_late.gif";
                            break;

                        case "2":
                            dt.Rows[i]["img_status"] = "frm_inbox_overdue.gif";
                            break;

                        case "3":
                            dt.Rows[i]["img_status"] = "frm_inbox_urgent.gif";
                            break;

                        case "4":
                            dt.Rows[i]["img_status"] = "frm_inbox_reassigned.gif";
                            break;

                        case "7":
                            dt.Rows[i]["img_status"] = "frm_inbox_urgent.gif";
                            break;

                        case "8":
                            dt.Rows[i]["img_status"] = "frm_inbox_reassigned.gif";
                            break;

                        case "16":
                            dt.Rows[i]["img_status"] = "frm_inbox_returned.gif";
                            break;

                        case "32":
                            dt.Rows[i]["img_status"] = "frm_inbox_resubmitted.gif";
                            break;

                        default:
                            dt.Rows[i]["img_status"] = "frm_initiate_blank.gif";
                            break;
                    }

                    //判断是否为指派、会办的任务类型
                    if (dt.Rows[i]["taskuser"].ToString() != dt.Rows[i]["assignedtouser"].ToString())
                    {
                        dt.Rows[i]["img_status"] = "frm_inbox_reassigned.gif";
                    }

                    //是否显示监控图标
                    if (dt.Rows[i]["taskid"] == DBNull.Value || dt.Rows[i]["taskid"].ToString().Trim() == "")
                    {
                        dt.Rows[i]["img_monitor"] = "frm_initiate_blank.gif";
                        dt.Rows[i]["img_status"]  = "frm_initiate_blank.gif";
                    }
                    else
                    {
                        dt.Rows[i]["img_monitor"] = "bpmview.gif";
                    }

                }

                //第一次没有排序字段的情况
                if (ViewState["OrderBy"] == null)
                {
                    dt.DefaultView.Sort = "starttime DESC";
                }
                else
                {
                    dt.DefaultView.Sort = ViewState["OrderBy"] + " " + ViewState["Order"];
                }

                rep.DataSource = dt;
                rep.DataBind();

                //加载下拉列表框
                load_drp_control_list(dt);

                //是否隐藏空白行对应的 CheckBox
                if (dt.Rows.Count == 1 && string.IsNullOrEmpty(dt.Rows[0]["taskid"].ToString()))
                { 
                    ((CheckBox)rep.Items[0].FindControl("chk_items")).Visible = false;
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 load_gv_inbox_list 方法出错：" + ee.Message);
            }
        }
        #endregion

        #region 方法 查询并对查询下拉列表进行填充
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void load_drp_control_list(DataTable dt)
        {
            try
            {
                #region 填充查询条件中的 流程名称、步骤名称 下拉框
                //增加第一行
                if (drpProcess.Items.Count == 0)
                {
                    drpProcess.Items.Add(new ListItem("All", "all"));
                }
                //drpStep.Items.Add(new ListItem("All", "all"));

                //数据合法性检查
                if (dt == null)
                {
                    return;
                }

                //循环所有的记录集
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    bool Flg = false;

                    //流程名称下拉列表
                    if (!string.IsNullOrEmpty(dt.Rows[i]["processname"].ToString()))
                    {
                        Flg = true;
                        foreach (ListItem item in drpProcess.Items)
                        {
                            if (dt.Rows[i]["processname"].ToString() == item.Value)
                            {
                                Flg = false;
                                break;
                            }
                        }
                    }

                    ////步骤名称下拉列表
                    //foreach (ListItem item in drpStep.Items)
                    //{
                    //    if (dt.Rows[i]["steplabel"].ToString() == item.Value)
                    //    {
                    //        Flg2 = false;
                    //        break;
                    //    }
                    //}

                    //如果不存在的情况
                    if (Flg)
                    {
                        drpProcess.Items.Add(new ListItem(dt.Rows[i]["processname"].ToString(), dt.Rows[i]["processname"].ToString()));
                    }

                    //if (Flg2)
                    //{
                    //    drpStep.Items.Add(new ListItem(dt.Rows[i]["steplabel"].ToString(), dt.Rows[i]["steplabel"].ToString()));
                    //}
                }
                #endregion
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 load_drp_control_list方法出错：" + ee.Message);
            }
        }
        #endregion

        #region 方法 执行任务指派
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void assign_tasks()
        {
            try
            {
                //数据合法性检查
                bool Flg = false;
                string strAssignToUser = txtAssignConferToAD.Value;

                //如果选择的是 仅限选择的任务 情况
                if (drpOptions.SelectedItem.Value == "A")
                {
                    //循环执行任务指派
                    foreach (RepeaterItem ri in gvInbox.Items)
                    {
                        Repeater rpt = ri.FindControl("dv_show") as Repeater;
                        ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;

                        if (imgG.CommandName == "Shrink")
                        {
                            foreach (RepeaterItem row in rpt.Items)
                            {
                                CheckBox chkRow = (CheckBox)row.FindControl("chk_items");

                                //如果是被选择的情况，执行任务指派
                                if (chkRow.Checked)
                                {
                                    string strTaskID = ((Label)row.FindControl("taskid")).Text.Trim();
                                    Task tskTemp = new Task();
                                    tskTemp.InitializeFromTaskId(strTaskID);
                                    Flg = tskTemp.AssignTask(strAssignToUser);
                                }
                            }
                        }
                    }
                }

                //如果选择的是 所有当前的任务 情况
                if (drpOptions.SelectedItem.Value == "B")
                {
                    User usrTemp = null;
                    OrgChart ocTemp = new OrgChart();
                    ocTemp.FindUser(clsCmm.comm_username, "", 0, out usrTemp);
                    Flg = usrTemp.AssignAllCurrentTasks(strAssignToUser);
                }

                //如果选择的是 所有将来的任务 情况
                if (drpOptions.SelectedItem.Value == "C")
                {
                    User usrTemp = null;
                    OrgChart ocTemp = new OrgChart();
                    ocTemp.FindUser(clsCmm.comm_username, "", 0, out usrTemp);

                    //日期数据检查
                    DateTime dteUntileDate = System.DateTime.Now.AddYears(20);
                    if (txtUntileDate.Text.Trim() != "")
                    {
                        dteUntileDate = System.Convert.ToDateTime(txtUntileDate.Text.Trim());
                    }

                    Flg = usrTemp.AssignAllFutureTasks(strAssignToUser, dteUntileDate.ToOADate());
                }

                //如果执行成功的情况，给出结果信息
                if (Flg)
                {
                    lblAssignConferErr.Text = clsCmm.getTextValue("frm_inbox_txt_assign_confer_success");
                }
                else
                {
                    lblAssignConferErr.Text = clsCmm.getTextValue("frm_inbox_txt_assign_confer_failed");
                }

                //查询并对列表进行数据绑定
                foreach (RepeaterItem ri in gvInbox.Items)
                {
                    ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;
                    Repeater rpt = ri.FindControl("dv_show") as Repeater;
                    strRange = imgG.CommandArgument.ToString().Split('~');

                    if (imgG.CommandName == "Shrink")
                    {
                        load_gv_inbox_list(rpt);
                    }
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 assign_tasks方法出错：" + ee.Message);
                lblAssignConferErr.Text = clsCmm.getTextValue("frm_inbox_txt_assign_confer_failed");
            }
        }
        #endregion

        #region 方法 执行任务会办
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void confer_tasks()
        {
            try
            {
                //数据合法性检查
                bool Flg = false;
                string strSQL = "";
                int intNum = 0;
                string strAssignToUser = txtAssignConferToAD.Value;

                //如果选择的是 仅限选择的任务 情况
                if (drpOptions.SelectedItem.Value == "A")
                {
                    //循环执行任务指派
                    foreach (RepeaterItem ri in gvInbox.Items)
                    {
                        Repeater rpt = ri.FindControl("dv_show") as Repeater;
                        ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;

                        if (imgG.CommandName == "Shrink")
                        {
                            foreach (RepeaterItem row in rpt.Items)
                            {
                                CheckBox chkRow = (CheckBox)row.FindControl("chk_items");

                                //如果是被选择的情况，执行任务指派
                                if (chkRow.Checked)
                                {
                                    string strTaskID = ((Label)row.FindControl("taskid")).Text.Trim();
                                    strSQL = "update tasks set substatus = 8, assignedtouser='" + strAssignToUser + "' where taskid = '" + strTaskID + "' and status = 1";
                                    clsCmm.clsDB.Storage("bpmDB");
                                    intNum = clsCmm.clsDB.ExcuteSql(strSQL);

                                    //是否执行成功
                                    if (intNum == 1)
                                    {
                                        Flg = true;
                                    }
                                }
                            }
                        }
                    }
                }

                //如果选择的是 所有当前的任务 情况
                if (drpOptions.SelectedItem.Value == "B")
                {
                    strSQL = "update tasks set substatus = 8, assignedtouser='" + strAssignToUser + "' where assignedtouser = '" + clsCmm.comm_username + "' and status = 1";
                    clsCmm.clsDB.Storage("bpmDB");
                    intNum = clsCmm.clsDB.ExcuteSql(strSQL);

                    //是否执行成功
                    if (intNum >= 1)
                    {
                        Flg = true;
                    }
                }

                //如果执行成功的情况，给出结果信息
                if (Flg)
                {
                    lblAssignConferErr.Text = clsCmm.getTextValue("frm_inbox_txt_assign_confer_success");
                }
                else
                {
                    lblAssignConferErr.Text = clsCmm.getTextValue("frm_inbox_txt_assign_confer_failed");
                }

                //查询并对列表进行数据绑定
                foreach (RepeaterItem ri in gvInbox.Items)
                {
                    ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;
                    Repeater rpt = ri.FindControl("dv_show") as Repeater;
                    strRange = imgG.CommandArgument.ToString().Split('~');

                    if (imgG.CommandName == "Shrink")
                    {
                        load_gv_inbox_list(rpt);
                    }
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 confer_tasks方法出错：" + ee.Message);
                lblAssignConferErr.Text = clsCmm.getTextValue("frm_inbox_txt_assign_confer_failed");
            }
        }
        #endregion

        #region 方法 执行任务收回
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void take_back_tasks()
        {
            try
            {
                //数据合法性检查
                bool Flg = false;
                string strAssignToUser = txtAssignConferToAD.Value;

                //循环执行任务指派
                foreach (RepeaterItem ri in gvInbox.Items)
                {
                    Repeater rpt = ri.FindControl("dv_show") as Repeater;
                    foreach (RepeaterItem row in rpt.Items)
                    {
                        CheckBox chkRow = (CheckBox)row.FindControl("chk_items");

                        //如果是被选择的情况，执行任务收回
                        if (chkRow.Checked)
                        {
                            string strTaskID = ((Label)row.FindControl("taskid")).Text.Trim();
                            Task tskTemp = new Task();
                            tskTemp.InitializeFromTaskId(strTaskID);
                            Flg = tskTemp.TakeBack(clsCmm.comm_username);
                        }
                    }
                }

                //如果执行成功的情况，给出结果信息
                if (Flg)
                {
                    lblTakeBackErr.Text = clsCmm.getTextValue("frm_inbox_txt_take_back_success");
                }
                else
                {
                    lblTakeBackErr.Text = clsCmm.getTextValue("frm_inbox_txt_take_back_failed");
                }

                //查询并对列表进行数据绑定
                foreach (RepeaterItem ri in gvInbox.Items)
                {
                    ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;
                    Repeater rpt = ri.FindControl("dv_show") as Repeater;
                    strRange = imgG.CommandArgument.ToString().Split('~');

                    if (imgG.CommandName == "Shrink")
                    {
                        load_gv_inbox_list(rpt);
                    }
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 assign_tasks方法出错：" + ee.Message);
                lblAssignConferErr.Text = clsCmm.getTextValue("frm_inbox_txt_assign_confer_failed");
            }
        }
        #endregion

        #region 方法 执行任务取消
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void cancel_tasks()
        {
            try
            {
                //数据合法性检查
                bool Flg = false;
                string strErr = "";
                string strAssignToUser = txtAssignConferToAD.Value;

                //循环执行任务指派
                foreach (RepeaterItem ri in gvInbox.Items)
                {
                    Repeater rpt = ri.FindControl("dv_show") as Repeater;
                    foreach (RepeaterItem row in rpt.Items)
                    {
                        CheckBox chkRow = (CheckBox)row.FindControl("chk_items");

                        //如果是被选择的情况，执行任务收回
                        if (chkRow.Checked)
                        {
                            //加载任务信息
                            string strTaskID = ((Label)row.FindControl("taskid")).Text.Trim();
                            Task tskTemp = new Task();
                            tskTemp.InitializeFromTaskId(strTaskID);

                            //加载实例信息
                            Incident incTemp = new Incident();
                            incTemp.LoadIncident(tskTemp.strProcessName, tskTemp.nIncidentNo);

                            //执行任务取消
                            Flg = incTemp.AbortIncident(clsCmm.comm_username, clsCmm.comm_userfullname + " " + System.DateTime.Now.ToString(), out strErr);
                        }
                    }
                }

                //如果执行成功的情况，给出结果信息
                if (Flg)
                {
                    lblTakeBackErr.Text = clsCmm.getTextValue("frm_inbox_txt_personal_info_success");
                }
                else
                {
                    lblTakeBackErr.Text = clsCmm.getTextValue("frm_inbox_txt_personal_info_failed");
                }

                //查询并对列表进行数据绑定
                foreach (RepeaterItem ri in gvInbox.Items)
                {
                    ImageButton imgG = ri.FindControl("imgGroup") as ImageButton;
                    Repeater rpt = ri.FindControl("dv_show") as Repeater;
                    strRange = imgG.CommandArgument.ToString().Split('~');

                    if (imgG.CommandName == "Shrink")
                    {
                        load_gv_inbox_list(rpt);
                    }
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 cancel_tasks 方法出错：" + ee.Message);
                lblAssignConferErr.Text = clsCmm.getTextValue("frm_inbox_txt_personal_info_failed");
            }
        }
        #endregion

        #region 方法 设置 Serach 条件 可见
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void set_e_element_tr_search_show()
        {
            try
            {
                lblAssignConferErr.Text = "";
                e_element_tr_search.Value = "block";
                e_element_tr_assign_tasks.Value = "none";
                e_element_tr_personal_infomation.Value = "none";

                if (e_element_tr_take_back.Value == "block")
                {
                    btnTakeBack.Visible = true;
                    btnTakebackAllFutureTask.Visible = is_future_task_has_assigned();
                    btnCancel.Visible = false;
                }
                else if (e_element_tr_cancel.Value == "block")
                {
                    btnTakeBack.Visible = false;
                    btnTakebackAllFutureTask.Visible = false;
                    btnCancel.Visible = true;
                }
                else
                {
                    btnTakeBack.Visible = false;
                    btnTakebackAllFutureTask.Visible = false;
                    btnCancel.Visible = false;
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 set_e_element_tr_search_show方法出错：" + ee.Message);
            }
        }
        #endregion

        #region 方法 设置 Assign & Confer 条件 可见
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void set_e_element_tr_assign_tasks_show()
        {
            try
            {
                lblAssignConferErr.Text = "";
                e_element_tr_search.Value = "none";
                e_element_tr_assign_tasks.Value = "block";
                e_element_tr_take_back.Value = "none";
                e_element_tr_cancel.Value = "none";
                e_element_tr_personal_infomation.Value = "none";
                btnTakeBack.Visible = false;
                btnTakebackAllFutureTask.Visible = false;
                btnCancel.Visible = false;
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 set_e_element_tr_assign_tasks_show方法出错：" + ee.Message);
            }
        }
        #endregion

        #region 方法 设置 Take Back 条件 可见
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void set_e_element_tr_take_back_show()
        {
            try
            {
                lblAssignConferErr.Text = "";
                e_element_tr_search.Value = "block";
                e_element_tr_assign_tasks.Value = "none";
                e_element_tr_take_back.Value = "block";
                e_element_tr_cancel.Value = "none";
                e_element_tr_personal_infomation.Value = "none";
                btnTakeBack.Visible = true;
                btnCancel.Visible = false;

                //设置“收回所有将来任务”按钮是否可见
                btnTakebackAllFutureTask.Visible = is_future_task_has_assigned();
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 set_e_element_tr_take_back_show方法出错：" + ee.Message);
            }
        }
        #endregion

        #region 方法 设置 Cancel 条件 可见
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void set_e_element_tr_cancel_show()
        {
            try
            {
                lblAssignConferErr.Text = "";
                e_element_tr_search.Value = "block";
                e_element_tr_assign_tasks.Value = "none";
                e_element_tr_take_back.Value = "none";
                e_element_tr_cancel.Value = "block";
                e_element_tr_personal_infomation.Value = "none";
                btnTakeBack.Visible = false;
                btnTakebackAllFutureTask.Visible = false;
                btnCancel.Visible = true;                
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 set_e_element_tr_cancel_show方法出错：" + ee.Message);
            }
        }
        #endregion

        #region 方法 设置 Personal Infomation 条件 可见
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void set_element_tr_personal_infomation_show()
        {
            try
            {
                e_element_tr_search.Value = "none";
                e_element_tr_assign_tasks.Value = "none";
                e_element_tr_take_back.Value = "none";
                e_element_tr_personal_infomation.Value = "block";
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 set_e_element_tr_take_back_show方法出错：" + ee.Message);
            }
        }
        #endregion

        #region 方法 取得同事列表
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void get_all_associate()
        {
            try
            {                
                User currentUser = new User();
                UserPreferences currentUserP = new UserPreferences();
                currentUser.strUserName = clsCmm.comm_username;

                //如果存在返回值的情况
                all_txtAssociateAD.Value = "";
                lblAllAssociate.Text = "";
                if (currentUser.GetUserPrefs(out currentUserP))
                {
                    //邮箱
                    txtEmail.Text = currentUserP.strEmail;

                    //同事列表
                    if (currentUserP.AssociatesList != null)
                    {
                        string strSplit = "";

                        //循环取得所有同事
                        for (int i = 0; i < currentUserP.AssociatesList.Length; i++)
                        {
                            if (i == 0)
                            {
                                strSplit = "";
                            }
                            else
                            {
                                strSplit = "; ";
                            }

                            all_txtAssociateAD.Value += strSplit + currentUserP.AssociatesList[i].strUserName;
                            lblAllAssociate.Text += strSplit + currentUserP.AssociatesList[i].strUserFullName;
                        }
                    }
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 get_all_associate 方法出错：" + ee.Message);
            }
        }
        #endregion

        #region 方法 设置同事列表
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void set_all_associate()
        {
            try
            {
                OrgChart currentOC = new OrgChart();
                User currentUser = new User();
                UserPreferences currentUserP = new UserPreferences();
                currentUser.strUserName = clsCmm.comm_username;

                //如果存在返回值的情况
                if (currentUser.GetUserPrefs(out currentUserP))
                {
                    //邮箱
                    User[] arrAssociate;
                    currentUserP.strEmail = txtEmail.Text;

                    //如果是新加入列表的情况
                    if (is_in_all_txtAssociate.Value == "add")
                    {
                        //临时变量
                        int intLen = 0;
                        string[] arrAssociateAD = all_txtAssociateAD.Value.Split(';');
                        if (all_txtAssociateAD.Value.Trim() == "")
                        {
                            intLen = 1;
                        }
                        else
                        {
                            intLen = arrAssociateAD.Length + 1;
                        }
                        arrAssociate = new User[intLen];

                        //循环取得所有同事
                        if (all_txtAssociateAD.Value.Trim() != "")
                        {
                            for (int i = 0; i < arrAssociateAD.Length; i++)
                            {
                                currentOC.FindUser(arrAssociateAD[i].Trim(), "", 0, out arrAssociate[i]);
                            }
                        }

                        //新加入的同事
                        currentOC.FindUser(txtAssociateAD.Value.Trim(), "", 0, out arrAssociate[arrAssociate.Length- 1]);
                        currentUserP.AssociatesList = arrAssociate;

                        //将同事加入临时表
                        clsCmm.clsDB.Storage("oleDB");
                        clsCmm.clsDB.ExcuteSql("insert into t_Associate(ass_name, ass_associate, ass_associate_name)values('" + clsCmm.comm_username + "','" + txtAssociateAD.Value.Trim() + "','" + arrAssociate[arrAssociate.Length - 1].strUserFullName + "')");
                    }

                    //如果是新加入列表的情况
                    if (is_in_all_txtAssociate.Value == "delete")
                    {
                        //临时变量
                        int intLoc = 0;
                        string[] arrAssociateAD = all_txtAssociateAD.Value.Split(';');
                        arrAssociate = new User[arrAssociateAD.Length - 1];

                        //循环取得所有同事
                        for (int i = 0; i < arrAssociateAD.Length && intLoc < arrAssociate.Length; i++)
                        {
                            //如果是待移出同事的情况
                            if (txtAssociateAD.Value.Trim().ToLower() == arrAssociateAD[i].Trim().ToLower())
                            {
                                continue;

                            }else
                            {
                                currentOC.FindUser(arrAssociateAD[i].Trim(), "", 0, out arrAssociate[intLoc]);
                                intLoc++;
                            }
                        }

                        //设置同事列表
                        currentUserP.AssociatesList = arrAssociate;

                        //将同事从临时表中移除
                        clsCmm.clsDB.Storage("oleDB");
                        clsCmm.clsDB.ExcuteSql("delete from t_Associate where ass_name='" + clsCmm.comm_username + "' and ass_associate='" + txtAssociateAD.Value.Trim() + "'");
                    }

                    //执行“设置同事”具体的保存操作                    
                    if (currentUser.SetUserPrefs(currentUserP))
                    {
                        lblAssociateErr.Text = clsCmm.getTextValue("frm_inbox_txt_personal_info_success");
                    }
                    else 
                    {
                        lblAssociateErr.Text = clsCmm.getTextValue("frm_inbox_txt_personal_info_failed");
                    }
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 set_all_associate 方法出错：" + ee.Message);
                lblAssociateErr.Text = clsCmm.getTextValue("frm_inbox_txt_personal_info_failed");
            }
        }
        #endregion

        #region 方法 判断是否已指派所有将来的任务
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool is_future_task_has_assigned()
        {
            try
            {
                int intCNT = 0;
                string strSQL = "select count(*) as cnt from assignment where taskuser='" + clsCmm.comm_username + "' and processname is null and stepid is null and steplabel is null and assignuntil is not null";
                clsCmm.clsDB.Storage("bpmDB");
                DataTable dt = clsCmm.clsDB.Query(strSQL);

                //如果结果返回值 > 1 的情况，返回 true，否则返回 false
                int.TryParse(dt.Rows[0]["cnt"].ToString(), out intCNT);
                if (intCNT >= 1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch
            {
                //TaskDB.Log("", false, "调用 inbox.aspx 页面 is_future_task_has_assigned方法出错：" + ee.Message);
                return false;
            }
        }
        #endregion
    }
}
